package com.CNMedical.system.service.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.diboot.core.service.impl.BaseServiceImpl;
import com.CNMedical.common.utils.DateUtils;
import com.CNMedical.system.domain.vo.AppletForumVO;
import com.CNMedical.system.service.IAppletForumCollectService;
import org.springframework.stereotype.Service;
import com.CNMedical.system.mapper.AppletForumMapper;
import com.CNMedical.system.domain.entity.AppletForum;
import com.CNMedical.system.service.IAppletForumService;

import javax.annotation.Resource;

/**
 * 帖子Service业务层处理
 * 
 * @author tang
 * @date 2023-03-28
 */
@Service
public class AppletForumServiceImpl extends BaseServiceImpl<AppletForumMapper, AppletForum> implements IAppletForumService
{
    @Resource
    private AppletForumMapper appletForumMapper;

    @Resource
    private IAppletForumCollectService appletForumCollectService;

    @Override
    public List<AppletForum> getMyForumList(String userId) {
        return lambdaQuery().eq(AppletForum::getUserId,userId).list();
    }

    @Override
    public AppletForumVO getForumDetailById(String forumId, String id) {
        AppletForum appletForum = getById(forumId);
        AppletForumVO appletForumVO = BeanUtil.toBean(appletForum, AppletForumVO.class);
        appletForumVO.setIsCollect(appletForumCollectService.checkWhetherCollect(forumId, id));
        return appletForumVO;
    }

    @Override
    public List<AppletForum> getAllForumPostList() {
        return lambdaQuery().list();
    }

    /**
     * 查询帖子
     * 
     * @param id 帖子主键
     * @return 帖子
     */
    @Override
    public AppletForum selectAppletForumById(Long id)
    {
        return appletForumMapper.selectAppletForumById(id);
    }

    /**
     * 查询帖子列表
     * 
     * @param appletForum 帖子
     * @return 帖子
     */
    @Override
    public List<AppletForum> selectAppletForumList(AppletForum appletForum)
    {
        return appletForumMapper.selectAppletForumList(appletForum);
    }

    /**
     * 新增帖子
     * 
     * @param appletForum 帖子
     * @return 结果
     */
    @Override
    public int insertAppletForum(AppletForum appletForum)
    {
        appletForum.setCreateTime(DateUtils.getNowDate());
        return appletForumMapper.insertAppletForum(appletForum);
    }

    /**
     * 修改帖子
     * 
     * @param appletForum 帖子
     * @return 结果
     */
    @Override
    public int updateAppletForum(AppletForum appletForum)
    {
        appletForum.setUpdateTime(DateUtils.getNowDate());
        return appletForumMapper.updateAppletForum(appletForum);
    }

    /**
     * 批量删除帖子
     * 
     * @param ids 需要删除的帖子主键
     * @return 结果
     */
    @Override
    public int deleteAppletForumByIds(Long[] ids)
    {
        return appletForumMapper.deleteAppletForumByIds(ids);
    }

    /**
     * 删除帖子信息
     * 
     * @param id 帖子主键
     * @return 结果
     */
    @Override
    public int deleteAppletForumById(Long id)
    {
        return appletForumMapper.deleteAppletForumById(id);
    }
}
